package com.foodsafe.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.foodsafe.dao.GoodsDao;
import com.foodsafe.model.Additive;
import com.foodsafe.model.Goods;
import com.foodsafe.util.PageInfo;

@Component("GoodsService")
public class GoodsService {
	private GoodsDao goodsDao;

	public GoodsDao getGoodsDao() {
		return goodsDao;
	}

	@Resource
	public void setGoodsDao(GoodsDao goodsDao) {
		this.goodsDao = goodsDao;
	}

	public List<Goods> queryGoods(String barCode, String goodsName)
			throws Exception {

		return this.goodsDao.queryGoods(barCode, goodsName);
	}

	public List<Additive> gainAdditivesByGoods(List<Goods> goods, int maxId)
			throws Exception {
		List<Additive> additives = new ArrayList<Additive>();
		for (Goods g : goods) {
			additives.addAll(this.goodsDao.gainAdditivesByGoods(g, maxId));
		}
		return additives;
	}

	public void addGoodsFromClient(Goods goods) throws Exception {
		this.goodsDao.addGoodsFromClient(goods);
	}

	public <T> List<T> updateData(Class<T> c, int maxId) throws Exception {

		return this.goodsDao.updateData(c, maxId);
	}

	public List<Goods> queryGoods(PageInfo pageInfo) throws Exception {

		return this.goodsDao.queryGoods(pageInfo);
	}

	public void deleteGoods(int[] goodsIds) throws Exception {
		this.goodsDao.deleteGoods(goodsIds);
	}

	public void addGoods(Goods goods) throws Exception {
		this.goodsDao.addGoods(goods);

	}

	public void editGoods(Goods goods) {
		this.goodsDao.editGoods(goods);

	}

	public Goods getGoodsInfoById(int id) throws Exception {

		return goodsDao.getGoodsInfoById(id);
	}
}
